package breadbox.pastry.routing;

import java.net.InetAddress;
import java.io.Serializable;

import breadbox.pastry.ID;

public class RoutingNode implements Comparable< RoutingNode >, Serializable {
	private static final long serialVersionUID = 142662373638686538L;
	private ID id_;
	private InetAddress ip_;
	private int port_;
	private int distance_;
	private RoutingNodeType type_;
	
	public RoutingNode( RoutingNode other ) {
		id_ = other.id_;
		ip_ = other.ip_;
		port_ = other.port_;
		distance_ = other.distance_;
		type_ = other.type_;
	}
	
	public RoutingNode( ID id ) {
		id_ = id;
	}
	
	public RoutingNode( ID id, InetAddress ip, int port ) {
		id_ = id;
		ip_ = ip;
		port_ = port;
		distance_ = 0;
		type_ = null;
	}
	
	public int getDistance( ) {
		return distance_;
	}
	
	public void setDistance( int d ) {
		distance_ = d;
	}
	
	public RoutingNodeType getType( ) {
		return type_;
	}
	
	public void setType( RoutingNodeType t ) {
		type_ = t;
	}
	
	public void setIp( InetAddress ip ) {
		ip_ = ip;
	}
	
	public void setPort( int port ) {
		port_ = port;
	}
	
	public int compareTo( RoutingNode rn ) {
		return id_.compareTo( rn.id_ );
	}
	
	public boolean equals( RoutingNode other ) {
		return compareTo( other ) == 0;
	}
	
	public ID getId( ) {
		return id_;
	}
	
	public InetAddress getIp( ) {
		return ip_;
	}
	
	public int getPort( ) {
		return port_;
	}
	
	public enum RoutingNodeType {
		LEAF,
		NEIGHBOR,
		ROUTE
	}
}
